home *** CD-ROM | disk | FTP | other *** search
- Emodules:Tools/thx-play.m (and Emodules:Tools/thx-play_020.m -- a 68020
- optimised version, not 68000 compatible)
-
- E interface to the THX2 player by Martin Wodok (Dexter/Abyss).
-
- Note: You need to read a THX module in from disk or INCBIN it, this is not
- one of the functions in thx-play.m. You should load it into PUBLIC memory,
- it does not have to be CHIP memory. The module 'tools/file' is handy for
- loading files from disk.
-
- Example source (see src/PlayTHX.e and src/PlayTHX_gui.e for more detailed
- example):
-
- MODULE 'tools/thx-play','tools/file'
- PROC main()
- DEF mod,vol
- IF mod:=loadfile(arg)
- IF thxInit(mod)=0
- thxPlay()
- REPEAT; WaitTOF(); UNTIL CtrlC() OR thxSongEnded()
- thxStop()
-
- thxFree()
- ENDIF
- freefile(mod)
- ENDIF
- ENDPROC
-
-
- Functions:
- -----------------------------------------------------------------------------
-
- NAME
- thxInit() -- initialise player and module.
-
- SYNOPSIS
- error=thxInit(moduleptr)
-
- FUNCTION
- Initialises the player (if needed) and initializes the module. You may also
- call thxInit(0) to initialise the player but not the module. Does not start
- to play the module until you call thxPlay(). You must call this each time
- you want to play a different module. The allocations made for the player
- are made only the first time you call thxInit(), no matter how many modules
- you want. If allocations fail, they will be automatically freed.
-
- INPUTS
- module - pointer to a THX module or 0
-
- RESULT
- error - 0 means all went OK, any other value means something FAILED.
-
- SEE ALSO
- thxFree(), thxPlay()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxFree() -- free resources held by player.
-
- SYNOPSIS
- void thxFree()
-
- FUNCTION
- Stops any THX module playing and frees resources used by the player. You
- can call this whether thxInit() suceeded or not.
-
- SEE ALSO
- thxInit()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxPlay() -- start playing the song.
-
- SYNOPSIS
- void thxPlay()
-
- FUNCTION
- Starts playing the module. If the module has just been initialised or
- stopped, or the subsong has just been changed, then play will start at the
- beginning of the song/subsong. Otherwise, it will continue from where it
- was paused.
-
- SEE ALSO
- thxStop(), thxPause()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxStop() -- stop playing a song/module.
-
- SYNOPSIS
- void thxStop()
-
- FUNCTION
- Stops the module. Can be restarted from the beginning again with thxPlay().
- If you call this, you can free the memory used by your thx module without
- calling thxFree() which has the unpleasant effect of requiring to
- recalculate all the filters if you call thxInit() again.
-
- SEE ALSO
- thxPlay(), thxFree()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxPause() -- pause play of a song.
-
- SYNOPSIS
- void thxPause()
-
- FUNCTION
- Pauses the playing module. Call thxPlay() to continue play again.
-
- SEE ALSO
- thxPlay()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxWind() -- wind the song forward or back.
-
- SYNOPSIS
- void thxWind(direction)
-
- FUNCTION
- Advances forward or backwards through the song by a specified number of
- positions. Please use the value 1 to skip forward and -1 to skip back, for
- future compatibility.
-
- INPUTS
- direction - if positive, winds on to the next position.
- if negative, winds back to the previous position,
- if 0, ignored.
-
- NOTE
- Be wary of stepping beyond the end of a song. Also note this function only
- takes effect once a frame or so.
-
- SEE ALSO
-
- -----------------------------------------------------------------------------
-
- NAME
- thxSetSong() -- set song to be played.
-
- SYNOPSIS
- thxSetSong(song)
-
- FUNCTION
- Sets which song to play, if a module contains more than one song. Most
- modules only contain one song, but some modules contain sub-songs as well
- as the main one. You can use this function to specify which one should be
- played. If you call this function and there is already a song playing, it
- will be stopped first.
-
- INPUTS
- song - 0 to set the main song to be played, any other number will change to
- that subsong, if it exists. Otherwise, no change will be made (other
- than the stoppage).
-
- NOTE
- It is up to you to start playing the module again.
-
- SEE ALSO
- thxGetNumSongs()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxGetNumSongs() -- get number of subsongs.
-
- SYNOPSIS
- songs=thxGetNumSongs()
-
- FUNCTION
- Returns the number of subsongs in the module, if any. You can use the
- thxSetSong() function to play one of the subsongs, if that's possible.
-
- RESULT
- songs - 0 if there are no subsongs (only the main song), otherwise returns
- the number of subsongs.
-
- SEE ALSO
- thxSetSong()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxSetVolume() -- set master volume.
-
- SYNOPSIS
- thxSetVolume(volume)
-
- FUNCTION
- Sets the master volume. Does not stop play.
-
- INPUTS
- volume - from 0 (silent) to 64 (loudest)
-
- NOTE
- This function can take up to two frames to take an audible effect.
- If song is paused, will not take effect until unpaused.
-
- SEE ALSO
- thxGetVolume()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxGetVolume() -- get master volume.
-
- SYNOPIS
- volume=thxGetVolume()
-
- FUNCTION
- Gets the current setting of the master volume. Does not stop play.
-
- RESULT
- volume - current volume setting from 0 (silent) to 64 (loudest)
-
- SEE ALSO
- thxSetVolume()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxSyncByte() -- get sync byte value.
-
- SYNOPIS
- value=thxSyncByte()
-
- FUNCTION
- Gets the current setting of the 'external timing' byte, which can be set to
- any byte value at any moment in time during play of the song BY the song
- itself, using the 8 command in the tracker. It's there to allow you to mark
- specific events in the music with the 8 command and a value, then wait
- until calling thxSyncByte() returns that value. The returned value doesn't
- change until another 8 command in the song changes it.
-
- NOTE
- Be very careful not to busy-wait on a new value if there is the possibility
- the song is paused or not playing.
-
- RESULT
- value - current value of the sync byte.
-
- SEE ALSO
-
- -----------------------------------------------------------------------------
-
- NAME
- thxSongEnded() -- detect if song has ended.
-
- SYNOPIS
- ended=thxSongEnded()
-
- FUNCTION
- Returns nonzero value if the player has detected the end of a song and is
- now looping.
-
- NOTE
- The detection of songend is crap (sorry Dexter :^)
-
- RESULT
- value - nonzero if song is now looping, zero otherwise.
-
- SEE ALSO
- thxSignalEnd()
-
- -----------------------------------------------------------------------------
-
- NAME
- thxSignalEnd() -- Signal() when song ends.
-
- SYNOPIS
- thxSignalEnd(signals)
-
- FUNCTION
- Asks THX to send the signals you specify back to you when the song ends. If
- songend occurs and the signal is sent, it will not be sent again unless you
- call thxSignalEnd() again to reload the trigger. The signal will also be
- cancelled if you call thxStop() directly, or indirectly through
- thxSetSong() or thxFree(). You may call this function at any time, even
- when the player is not initialised, or while a song is playing. The task
- you call it from is stored, so don't call it from asynchroneous threads
- that may disappear before songend is reached.
-
- NOTE
- The detection of songend is crap (sorry Dexter :^)
-
- INPUT
- signals - a 32bit set of signals, eg (SIGBREAKF_CTRL_C OR SIGBREAKF_CTRL_D)
- to be sent back to calling task when songend occurs.
-
- SEE ALSO
- thxSongEnded(), exec.library/Signal()
-
- -----------------------------------------------------------------------------
-
- Kyzer/CSG, 8-Oct-1997